package com.scs.application.modules.order.excel.handler;
/**
 * @Description:
 */

import cn.afterturn.easypoi.handler.impl.ExcelDataHandlerDefaultImpl;
import com.scs.application.core.utils.Reflections;
import com.scs.application.core.utils.SpringHolder;
import com.scs.application.core.utils.StringUtils;
import com.scs.application.core.utils.UserUtils;
import com.scs.application.modules.base.entity.HospitalSupplier;
import com.scs.application.modules.base.service.HospitalSupplierService;
import com.scs.application.modules.order.dto.PurchaseOrderDTO;

/**
 * @ClassName HospitalSupplierDataHandler
 * @Description TODO
 */
public class HospitalSupplierDataHandler extends ExcelDataHandlerDefaultImpl<PurchaseOrderDTO> {


    public String[] getNeedHandlerFields() {
        return new String[]{"供应商名称"};
    }

    public Object importHandler(PurchaseOrderDTO obj, String name, Object value) {
        if (!"供应商名称".equalsIgnoreCase(name)) {
            return null;
        }
        if (value == null || StringUtils.isBlank(value.toString())) {
            return null;
        }
        String supplierName = value.toString();

        HospitalSupplierService hospitalSupplierService = SpringHolder.getBean(HospitalSupplierService.class);
        String hospitalId = UserUtils.getHospitalId();
        HospitalSupplier hospitalSupplier = hospitalSupplierService.findBySupplierName(supplierName, hospitalId);

        if (hospitalSupplier != null && Reflections.getAccessibleField(obj, "supplierId") != null) {
            Reflections.setFieldValue(obj, "supplierId", hospitalSupplier.getId());
        }
        return null;
    }


}
